//
//  ZzscjlVC.swift
//  Auscultation
//
//  Created by 来 on 2020/12/22.
//

import UIKit

class ZzscjlVC: BaseVC {

    var id: String = ""
    
    var scrollView: UIScrollView!
    
    var ybqk: LGFLoginImageTitleView!
    var bz_p: UILabel!
    var ybqk_s: LGFSegmentView!
    var bzxz: LGFLoginImageTitleView!
    var bz: UITextView!
    var bzxz_s: LGFSegmentView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        initUI()
        ybqk_s.callIndex = { [weak self] (index) in
            if index == 1 {
                self?.bzxz.isHidden = false
                self?.bzxz.snp.updateConstraints({ (make) in
                    make.top.equalTo(self!.ybqk.snp.bottom).offset(10)
                    make.height.equalTo(44.lgf_H())
                })
            } else {
                self?.bzxz.isHidden = true
                self?.bzxz.snp.updateConstraints({ (make) in
                    make.top.equalTo(self!.ybqk.snp.bottom).offset(0)
                    make.height.equalTo(0)
                })
            }
        }
    }

    @objc func s_bc() {
        if ybqk_s.selectIndex == 1 && bzxz_s.selectIndexs.count == 0 {
            SVProgressHUD.showError("请选择病种")
            return
        }
        var condition: [String] = []
        bzxz_s.selectIndexs.forEach { (i) in
            condition.append(["VSD", "ASD", "PDA", "PS", "TOF"][i])
        }
        let paramet: [String: Any] = [
            "disease": condition.joined(separator: ","),
            "condition": ybqk_s.selectIndex.description,
            "remake": bz.text ?? "",
            "createdTime": Date().lgf_TimeStampString()
        ]
        EWERequest.lgf("screening/" + id + "/assess", paramet, .post, JSONEncoding.default) { (data) in
            SVProgressHUD.showSuccess("保存成功")
            Timer.lgf_After(S: 0.5) {
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ReloadScxqVC"), object: nil)
                self.navigationController?.popViewController(animated: true)
            }
        } _: { (error) in
            SVProgressHUD.showError(error)
        }
    }

}
